package com.ruoyi.xh.controller;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.core.page.TablePageDataInfo;
import com.ruoyi.common.core.domain.CommentResult;
import com.ruoyi.xh.domain.XhSystemRole;
import com.ruoyi.xh.service.IXhSystemRoleService;

/**
 * 权限Controller
 *
 * @author songjw
 * @date 2024-12-13
 */
@Api(tags = "权限Controller",value = "权限Controller")
@RestController
@RequestMapping("/xh/systemRole")
public class XhSystemRoleController extends BaseController {

    @Autowired
    private IXhSystemRoleService xhSystemRoleService;

    /**
     * 查询权限列表
     */
    @PreAuthorize("@ss.hasPermi('xh:systemRole:list')")
    @GetMapping("/list")
    @ApiOperation("查询权限列表")
    public TablePageDataInfo<XhSystemRole> list(XhSystemRole xhSystemRole) {
        return TablePageDataInfo.success(xhSystemRoleService.selectXhSystemRoleList(xhSystemRole));
    }

    /**
     * 获取权限详细信息
     */
    @PreAuthorize("@ss.hasPermi('xh:systemRole:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation("获取权限详细信息")
    public CommentResult<XhSystemRole> getInfo(@PathVariable("id") Long id) {
        return CommentResult.success(xhSystemRoleService.selectXhSystemRoleById(id));
    }

    /**
     * 新增权限
     */
    @PreAuthorize("@ss.hasPermi('xh:systemRole:add')")
    @Log(title = "权限", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增权限")
    public CommentResult<XhSystemRole> add(@RequestBody XhSystemRole xhSystemRole) {
            xhSystemRoleService.insertXhSystemRole(xhSystemRole);
        return CommentResult.success();
    }

    /**
     * 修改权限
     */
    @PreAuthorize("@ss.hasPermi('xh:systemRole:edit')")
    @Log(title = "权限", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改权限")
    public CommentResult<XhSystemRole> edit(@RequestBody XhSystemRole xhSystemRole) {
            xhSystemRoleService.updateXhSystemRole(xhSystemRole);
        return CommentResult.success();
    }

    /**
     * 删除权限
     */
    @PreAuthorize("@ss.hasPermi('xh:systemRole:remove')")
    @Log(title = "权限", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    @ApiOperation("删除权限")
    public CommentResult<XhSystemRole> remove(@PathVariable Long[] ids) {
            xhSystemRoleService.deleteXhSystemRoleByIds(ids);
        return CommentResult.success();
    }
}
